import { SpiritEquipBasePanel } from "./SpiritEquipBasePanel";
import { Cache } from "../../cache/Cache";
import { ECategory } from "../../../../Message/Public/ECategory";
import { DataProvider } from "../../../../fl/data/DataProvider";
import { ItemData } from "../../resource/info/ItemData";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { MsgManager } from "../../manager/MsgManager";
import { Language } from "../../../../extend/language/Language";
import { ObjCreate } from "../common/ObjCreate";
import { SpiritEquipHDPlayer } from "../spiritEquip/SpiritEquipHDPlayer";
import { ImagesConst } from "../../resource/ImagesConst";
import { GlobalStyle } from "../../../common/global/GlobalStyle";
import { SpiritEquipPanel } from "../spiritEquip/SpiritEquipPanel";
import { EquipmentBgItem } from "./EquipmentBgItem";
import { SuitAttributePanel } from "../spiritEquip/SuitAttributePanel";
import { GlobalClass } from "../../../../com/mui/core/GlobalClass";
import { MuiEvent } from "../../../../com/mui/events/MuiEvent";
import { FilterConst } from "../../../component/gconst/FilterConst";
import { GameDefConfig } from "../../resource/GameDefConfig";
import { ESpiritEquipExType } from "../../../../Message/Public/ESpiritEquipExType";
import { GTextFiled } from "../../../../com/mui/controls/GTextFiled";
import { GImageButtonTabBar } from "../../../../com/mui/controls/GImageButtonTabBar";
import { GButton } from "../../../../com/mui/controls/GButton";
type int = number;
//class SpiritEquipEatPanel
    
    export  class SpiritEquipEatPanel extends SpiritEquipBasePanel
    {
        constructor()
        {
            super();
            this._circleBgArr = [];
            this._equipShowItems = [];
            return;
        }

        public /* override */ spiritEquipUpdate(): void
        {
            super.spiritEquipUpdate();
            var loc1=Cache.instance.spiritEquip.enEnableDragonSuitInfo;
            var loc2=Cache.instance.spiritEquip.enEatedDragonNum;
            this._suitAttPanel.updateSuitAtt(loc1);
            this._suitAttPanel.updateActiveNum(loc2);
            this._suitAttPanel.updateSkillList(Cache.instance.spiritEquip.getSkillsArray());
            return;
        }

        public /* override */ updateEquipList(): void
        {
            var loc1=Cache.instance.pack.rolePackCache.getSpiritEquipItemsByType(ECategory._ECategorySpiritEquip, this.getExType());
            _equipList.dataProvider = new DataProvider(this.getEquipItemsByLevel(loc1));
            if (this._bwItem.itemData) 
            {
                if (_equipList.dataProvider.getItemIndex(this._bwItem.itemData) == -1) 
                {
                    this.clickRightEquipItem(null);
                }
            }
            var loc2=Cache.instance.pack.rolePackCache.getSpiritEquipHDArray();
            this._spiritEquipPanel.updateSpiritEquip(loc2);
            return;
        }

        public eatSuccess(): void
        {
            this.clickRightEquipItem(null);
            return;
        }

        public selectDefaultTab(): void
        {
            this._imageBtnBar.selectedIndex = Cache.instance.spiritEquip.getEatedSuitNum();
            return;
        }

        protected /* override */ clickRightEquipItem(arg1: ItemData, arg2: Boolean=false): void
        {
            if (arg2) 
            {
                if (arg1) 
                {
                    if (Cache.instance.spiritEquip.isHadEat(arg1)) 
                    {
                        return;
                    }
                    Dispatcher.dispatchEvent(new DataEvent(EventName.WardrobeUndress, {"uid": arg1.uid, "index": arg1.effectEx}));
                }
            }
            else 
            {
                if (arg1) 
                {
                    if (!this.isCanEat()) 
                    {
                        MsgManager.showRollTipsMsg(Language.getString(36648));
                        return;
                    }
                    if (Cache.instance.spiritEquip.isHadEat(arg1)) 
                    {
                        MsgManager.showRollTipsMsg(Language.getString(36651));
                        return;
                    }
                }
                this._bwItem.itemData = arg1;
                this._spiritEquipPanel.selectByItemData(arg1);
            }
            return;
        }

        protected /* override */ createDisposedChildrenImpl(): void
        {
            var loc2=null;
            this._bgBitmap = new Object /* flash.display.Bitmap */();
            this._bgBitmap.y = -2;
            this.addChild(this._bgBitmap);
            ObjCreate.createFlowerBg(5, 320, 378, 159, this);
            this._hdPlayer = new SpiritEquipHDPlayer();
            this._hdPlayer.x = 200;
            this._hdPlayer.y = 190;
            addChild(this._hdPlayer);
            this._hdBitmap = new Object /* flash.display.Bitmap */();
            this._hdBitmap.x = 120;
            this._hdBitmap.y = 83;
            this.addChild(this._hdBitmap);
            this._bwbgBitmap = new Object /* flash.display.Bitmap */();
            this._bwbgBitmap.x = 90;
            this._bwbgBitmap.y = 216;
            this.addChild(this._bwbgBitmap);
            this._tsbwBitmap = new Object /* flash.display.Bitmap */();
            this._tsbwBitmap.x = 153;
            this._tsbwBitmap.y = 206;
            this.addChild(this._tsbwBitmap);
            ObjCreate.createBg(110, 15, 180, 20, this, ImagesConst.FightingStrgBg);
            this._nameTxt = ObjCreate.createGTextField(Language.getString(36640), 110, 15, 180, 20, this, GlobalStyle.textFormat6);
            this._nameTxt.autoSize = flash.text.TextFieldAutoSize.CENTER;
            this._spiritEquipPanel = new SpiritEquipPanel();
            this._spiritEquipPanel.y = 60;
            this.addChild(this._spiritEquipPanel);
            this._bwItem = new EquipmentBgItem();
            this._bwItem.move(180, 240);
            this.addChild(this._bwItem);
            this._bwItem.addEventListener(flash.events.MouseEvent.CLICK, this.onBwItemClickHandler);
            this._eatBtn = ObjCreate.createGButton(Language.getString(36644), 160, 415, 70, 24, this, "ButtonYellow");
            this._eatBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onEatBtnClickHandler);
            ObjCreate.createBg(15, 450, 365, 2, this, ImagesConst.SplitLine);
            ObjCreate.createGTextField(Language.getString(36641), 80, 290, 300, 20, this, GlobalStyle.textFormatGreen);
            this._suitAttPanel = new SuitAttributePanel();
            this._suitAttPanel.x = 10;
            this._suitAttPanel.y = 350;
            this.addChild(this._suitAttPanel);
            var loc1=[{"name":"spirit0", "styleName":"SpiritEquip0"}, {"name":"spirit1", "styleName":"SpiritEquip1"}, {"name":"spirit2", "styleName":"SpiritEquip2"}, {"name":"spirit3", "styleName":"SpiritEquip3"}, {"name":"spirit4", "styleName":"SpiritEquip4"}];
            var loc3=405;
            var loc4=15;
            var loc5=0;
            while (loc5 < 5) 
            {
                loc2 = ObjCreate.createBitmap(null, loc3, loc4, this);
                this._circleBgArr.push(loc2);
                loc3 = loc3 + 59;
                ++loc5;
            }
            super.createDisposedChildrenImpl();
            this._imageBtnBar = ObjCreate.createGImageButtonTabBar(398, 16, loc1, 51, 51, this, this.onTabBarChangeHandler);
            this._imageBtnBar.horizontalGap = 8;
            return;
        }

        protected /* override */ onResLoadedHandler(): void
        {
            var loc1=null;
            super.onResLoadedHandler();
            this._bgBitmap.bitmapData = GlobalClass.getBitmapData(ImagesConst.SpiritEquipEatBg);
            this._hdBitmap.bitmapData = GlobalClass.getBitmapData(ImagesConst.SpiritEquipHd);
            this._bwbgBitmap.bitmapData = GlobalClass.getBitmapData(ImagesConst.SpiritEquipBwBg);
            this._tsbwBitmap.bitmapData = GlobalClass.getBitmapData(ImagesConst.SpiritEquipTsbw);
            ObjCreate.createBitmap(ImagesConst.SpiritEquipAddAttr, 105, 327, this);
            var loc2=0;
            while (loc2 < 5) 
            {
                loc1 = this._circleBgArr[loc2];
                loc1.bitmapData = GlobalClass.getBitmapData(ImagesConst.CircleBtnBg);
                ++loc2;
            }
            this.updateSuitNameBitmap();
            return;
        }

        /* internal  */onBwItemClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            this.clickRightEquipItem(null);
            _equipList.selectedIndex = -1;
            return;
        }

        /* internal  */onEatBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=this._bwItem.itemData;
            if (loc1) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.SpiritEquipEat, loc1.uid));
            }
            return;
        }

        /* internal  */onTabBarChangeHandler(arg1: MuiEvent=null): void
        {
            var loc1=null;
            _equipList.selectedIndex = -1;
            this.clickRightEquipItem(null);
            this._exType = this.getExType();
            this._spiritEquipPanel.updatePosIndex(this._exType);
            loc1 = this._circleBgArr[this._preSelectedIdx];
            if (loc1) 
            {
                loc1.filters = [];
            }
            loc1 = this._circleBgArr[this._imageBtnBar.selectedIndex];
            if (loc1) 
            {
                loc1.filters = [FilterConst.gradientGlowFilter];
            }
            this._preSelectedIdx = this._imageBtnBar.selectedIndex;
            this.updateSuitNameBitmap();
            this.updateEquipList();
            return;
        }

        /* internal  */getEquipItemsByLevel(arg1: Array<any>): Array<any>
        {
            var loc2=null;
            var loc3=0;
            var loc4=0;
            this.resetEquipShowItems();
            var loc1=arg1.length;
            var loc5=0;
            while (loc5 < loc1) 
            {
                loc2 = arg1[loc5];
                loc3 = 0;
                loc4 = 0;
                if (loc2) 
                {
                    loc3 = GameDefConfig.instance.getSpiritEquipMaxStrength(loc2.color);
                    if (loc2.itemExInfo) 
                    {
                        loc4 = loc2.itemExInfo.sp_eq_str;
                    }
                    if (loc4 < loc3) 
                    {
                        this._equipShowItems[loc2.type] = loc2;
                    }
                }
                ++loc5;
            }
            return this._equipShowItems;
        }

        /* internal  */resetEquipShowItems(): void
        {
            this._equipShowItems.splice(0, 8);
            var loc1=0;
            while (loc1 < 8) 
            {
                this._equipShowItems.push(null);
                ++loc1;
            }
            return;
        }

        /* internal  */getExType(): int
        {
            var loc1=ESpiritEquipExType._ESpiritEquipExDragon;
            var loc2=this._imageBtnBar.selectedIndex;
            switch (loc2) 
            {
                case 0:
                {
                    loc1 = ESpiritEquipExType._ESpiritEquipExDragon;
                    break;
                }
                case 1:
                {
                    loc1 = ESpiritEquipExType._ESpiritEquipExTiger;
                    break;
                }
                case 2:
                {
                    loc1 = ESpiritEquipExType._ESpiritEquipExSuzaku;
                    break;
                }
                case 3:
                {
                    loc1 = ESpiritEquipExType._ESpiritEquipExBasaltic;
                    break;
                }
                case 4:
                {
                    loc1 = ESpiritEquipExType._ESpiritEquipExKirin;
                    break;
                }
            }
            return loc1;
        }

        /* internal  */updateSuitNameBitmap(): void
        {
            if (_isResLoaded) 
            {
                _tzBitmap.bitmapData = GlobalClass.getBitmapData("SpiritEquipWord" + this._exType);
            }
            return;
        }

        /* internal  */isCanEat(): Boolean
        {
            var loc1=this._imageBtnBar.selectedIndex + 1;
            var loc2=Cache.instance.spiritEquip.getMaxEatType();
            return loc1 <= loc2;
        }

        /* internal */ /* var */_bgBitmap: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_nameTxt: GTextFiled;

        /* internal */ /* var */_hdPlayer: SpiritEquipHDPlayer;

        /* internal */ /* var */_hdBitmap: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_bwbgBitmap: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_tsbwBitmap: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_spiritEquipPanel: SpiritEquipPanel;

        /* internal */ /* var */_bwItem: EquipmentBgItem;

        /* internal */ /* var */_imageBtnBar: GImageButtonTabBar;

        /* internal */ /* var */_eatBtn: GButton;

        /* internal */ /* var */_suitAttPanel: SuitAttributePanel;

        /* internal */ /* var */_exType: int=1;

        /* internal */ /* var */_preSelectedIdx: int;

        /* internal */ /* var */_circleBgArr: Array<any>;

        /* internal */ /* var */_equipShowItems: Array<any>;
    }
